package cn.kgc.tongxun.service;

import cn.kgc.tongxun.mapper.ContactMapper;
import cn.kgc.tongxun.pojo.Contact;
import cn.kgc.tongxun.pojo.ContactExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class ContactServiceImpl implements ContactService {
    @Resource
    ContactMapper contactMapper;
    @Override
    public PageInfo<Contact> seleContact(String cname,Integer pageNum) {
        PageHelper.startPage(pageNum,1);
        List<Contact> contacts;
        if(!"".equals(cname)){
        ContactExample example=new ContactExample();
        ContactExample.Criteria criteria = example.createCriteria();
        criteria.andCnameLike("%"+cname+"%");
        contacts = contactMapper.selectByExample(example);
    }else{
        contacts = contactMapper.selectByExample(null);
    }
    PageInfo<Contact> pageInfo=new PageInfo<>(contacts);
        return pageInfo;
    }

    @Override
    public Integer add(Contact contact) {
        return contactMapper.insert(contact);
    }
}
